<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;

/* @var $this yii\web\View */
/* @var $searchModel app\modules\Finance\models\InvoiceSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app.invoice', 'Invoices');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="invoice-index">

    <h2 class="page-header">
        <small><?= Html::encode($this->title) ?></small>
    </h2>

    <?php Pjax::begin(); ?> 
    <?php  echo $this->render('_search', ['model' => $searchModel]); ?> 
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        //'filterModel' => $searchModel,
        'layout'  =>  "{items}\n{pager}",
        'columns' => [
            //['class' => 'yii\grid\SerialColumn'],

            [
                'attribute' => 'user_id',
                //'filter' =>  $user,
                'value' => function ($model) {
                    return isset($model->user_id) ? $model->user->profile->name : '(未设置)' ;
                },
            ],
            [
                'attribute' => 'finance_id',
                //'filter' =>  $user,
                'value' => function ($model) {
                    return isset($model->finance->code) ? $model->finance->code : '(未设置)' ;
                },
            ],
            'code',
            // 'name',
            [
                'attribute' => 'name',
                //'filter' =>  $user,
                'value' => function ($model) {
                    return isset($model->name) ? \yii::$app->params['invoice_name'][$model->name] : '(未设置)' ;
                },
            ],
            'company',
            //'tax',
            //'bank_account',
            // 'bank_name',
            // 'address',
            // 'phone',
            // 'remark',
            // 'status',
            // 'user_id',
            // 'created_at',
            // 'updated_at',
            [
                    'attribute' => '金额',
                    'filter' =>  false,
                    'value' => function ($model) {
                        return Yii::$app->formatter->asCurrency($model->orderPrice);
                    },
                    'format' => 'raw',
            ],
           
            [
                'label'=>'操 作',
                'format'=>'raw',
                'value' => function($model){
                    $url = sprintf("/finance/invoice/view?id=%d", $model->id);
                    return Html::a('<i class="glyphicon glyphicon-eye-open"></i>',$url,['title' => '操作']);
                }
            ],
            
            [
                'label'=>'修改',
                'format'=>'raw',
                'value' => function($model){
                    
                       $url = sprintf("/finance/finance/view?id=%d", $model->finance_id);
                       $str = Html::a('<i class="glyphicon glyphicon-pencil"></i>',$url,['title' => '修改', 'target'=>'_blank']);
                       return $str;
                }
            ],
            [
                'label'=>'审批',
                'format'=>'raw',
                'value' => function($model){
                    if(\Yii::$app->user->can('is_finance') || \Yii::$app->user->can('is_admin')){
                       $r =  urlencode(\yii::$app->request->getUrl());

                       $url = sprintf("/finance/finance/finance-check?id=%d", $model->finance_id);
                       $str = Html::a('<i class="fa fa-check-square-o"></i>',$url,['title' => '审批', 'target'=>'_blank']);
                       return $str;
                    }else{
                        return " - ";
                    }
                }
            ],
        ],
    ]); ?>
    <?php Pjax::end(); ?>
</div>
